const mongoose = require('../db')
var md5 = require('md5')

const UserSchema = mongoose.Schema({
  username: { type: String, trim: true, required: true },
  password: {
    type: String,
    required: true,
    set(val) {
      return md5(val + 'xuhua.top')
    },
  },
  avatar: {
    type: String,
    default:
      'https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=2344451607,2404623174&fm=11&gp=0.jpg',
  },
  token: {
    type: String,
    default: '',
  },
  createtime: { type: Date, default: Date.now },
  updatetime: { type: Date, default: Date.now },
})

module.exports = mongoose.model('User', UserSchema, 'user')
